package org.gdkm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.gdkm.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.MyMapper;

@Service
@Transactional(readOnly = true)
public abstract class BaseServiceImpl<T , D extends MyMapper<T>> implements BaseService<T>{

    @Autowired
    private D dao;

    @Override
    @Transactional(readOnly = false)
    public int insert(T t) {
        int insert = dao.insert(t);
        return insert;
    }

    @Override
    @Transactional(readOnly = false)
    public int delete(T t) {
        int delete = dao.delete(t);
        return delete;
    }

    @Override
    @Transactional(readOnly = false)
    public int update(T t) {
        int update = dao.updateByPrimaryKey(t);
        return update;
    }

    @Override

    public T selectOne(T t) {
        T selectOne = dao.selectOne(t);
        return selectOne;
    }

    @Override
    public int count(T t) {
        int i = dao.selectCount(t);
        return i;
    }

    @Override
    public PageInfo<T> page(int pageNumber, int pageSize,T t) {
        PageHelper pageHelper=new PageHelper();
        pageHelper.startPage(pageNumber, pageSize);
        PageInfo<T> pageInfo=new PageInfo<>(dao.select(t));
        return pageInfo;
    }
}
